package ma.xin.shi.configurations.Service;

import java.util.ArrayList;
import java.util.List;
import ma.xin.shi.AutorsarCommonUtils;

public class ServiceConfig {
    private List<ServiceEntry> serviceList = new ArrayList<>();
 
    // ===== 添加service实例 =====
    public void addService(ServiceEntry entry) {
        serviceList.add(entry);
    }

    public boolean removeService(String name) {
        return serviceList.removeIf(s -> s.getServiceName().equals(name));
    }

    public List<ServiceEntry> getAllServices() {
        return new ArrayList<>(serviceList);
    }

    public ServiceEntry getServiceByName(String name) {
        for (ServiceEntry entry : serviceList) {
            if (entry.getServiceName().equals(name)) {
                return entry;
            }
        }
        return null;
    }

    public boolean updateService(String oldName, ServiceEntry updatedEntry) {
        for (int i = 0; i < serviceList.size(); i++) {
            if (serviceList.get(i).getServiceName().equals(oldName)) {
                serviceList.set(i, updatedEntry);
                return true;
            }
        }
        return false;
    }

    /**
     * 通过服务名称判断是否服务存在
     */
    public boolean serviceExistStatus(String serviceName) {
    	if (getServiceByName(serviceName) != null) {
    		AutorsarCommonUtils.logEx("服务已存在: " + serviceName);
            return true;
        }

        return false;
    }

    /**
     * 添加一个只有名称和ID的服务（空内容）
     */
    public boolean addServiceEx(String serviceName, int serviceId) {
    	if (getServiceByName(serviceName) != null) {
    		AutorsarCommonUtils.logEx("❌ 服务已存在: " + serviceName);
            return false;
        }

    	ServiceEntry entry = new ServiceEntry();
        entry.setServiceName(serviceName);
        entry.setServiceId(serviceId);
        serviceList.add(entry);

        return true;
    }

    /**
     * 如果服务不存在，则创建，如存在则直接返回。保证同名服务只有一个的条目
     */
    public void creatServiceIfNotExist(String serviceName) {
    	if (false == serviceExistStatus(serviceName)) {
    		ServiceEntry entry = new ServiceEntry();
    		entry.setServiceName(serviceName);
    		addService(entry);
    	}
    }

    /**
     * set serviceID from name
     */
    public void setServiceId(String serviceName, String serviceId) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            service.setServiceId(Integer.parseInt(serviceId.trim()));
        }else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }

    /**
     * 在指定服务中， 根据服务名获取服务ID
     */
    public String getServiceIDFromServiceName(String serviceName) {
        for (ServiceEntry entry : serviceList) {
            if (serviceName.equals(entry.getServiceName())) {
                return Integer.toString(entry.getServiceId());
            }
        }
        return null; // 没有找到返回 null
    }

    /**
     * Get Event list
     */
    public List<ServiceEventConfig> getEventsFromServiceName(String serviceName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            return service.getEvents();
        }
        return null;
    }

    /**
     * 向指定服务中添加 Event
     */
    public boolean addEventToService(String serviceName, ServiceEventConfig event) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            service.getEvents().add(event);
            return true;
        }
        return false;
    }
    
    /**
     * 向指定服务中添加 Event实例，只存储event name
     */
    public void addEvententryToService(String serviceName, String eventName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
        	ServiceEventConfig entry = new ServiceEventConfig();
        	entry.setEventName(eventName);
            service.getEvents().add(entry);
        }
    }
    
    /**
     * 在指定服务中 检查 特定event是否存在
     */
    public boolean isEventOfServiceExist(String serviceName, String eventName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            return service.isEventExistFromName(eventName);
        }
        return false;
    }

    /**
     * 在指定服务中 检查 特定event是否存在,如果不存在则创建这个event
     */
    public void creatEventOfServiceIfNotExist(String serviceName, String eventName) {
        if (serviceExistStatus(serviceName) == false) {
        	AutorsarCommonUtils.logEx("服务不存在: " + serviceName);
        	return;
        }
        
        if (isEventOfServiceExist(serviceName, eventName) == false) {
        	addEvententryToService(serviceName, eventName);
        }
    }

    /**
     * 在指定服务中 删除 特定event
     */
    public boolean removeEventFromService(String serviceName, String eventName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            List<ServiceEventConfig> events = service.getEvents();
            return events.removeIf(event -> event.getEventName().equals(eventName));
        }
        return false;
    }

    /**
     * 在指定服务中 修改 特定Event 的 protocol （通过Name）
     */
    public void setEventProtocol(String serviceName, String eventName, String protocol) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("eventName: " + eventName);
    	AutorsarCommonUtils.logEx("protocol: " + protocol);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig method = service.findEventByName(eventName);
            if (null != method) {
            	method.setRPCProtocol(protocol);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Event 的 protocol （通过Name）
     */
    public String getEventProtocol(String serviceName, String eventName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("eventName: " + eventName);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig method = service.findEventByName(eventName);
            if (null != method) {
            	return method.getRPCProtocol();
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            	return null;
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        	return null;
        }
    }

    /**
     * 在指定服务中 修改 特定Event 的 ID （通过Name）
     */
    public void setEventID(String serviceName, String eventName, String id) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("eventName: " + eventName);
    	AutorsarCommonUtils.logEx("id: " + id);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig method = service.findEventByName(eventName);
            if (null != method) {
            	method.setEventId(Integer.parseInt(id.trim()));
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Event 的 protocol （通过Name）
     */
    public void setEventGroupName(String serviceName, String eventName, String gName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("eventName: " + eventName);
    	AutorsarCommonUtils.logEx("gName: " + gName);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig method = service.findEventByName(eventName);
            if (null != method) {
            	method.setGroupName(gName);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Event 的 Id （通过Name）
     */
    public void setEventGroupId(String serviceName, String eventName, String id) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("eventName: " + eventName);
    	AutorsarCommonUtils.logEx("id: " + id);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig method = service.findEventByName(eventName);
            if (null != method) {
            	method.setGroupId(Integer.parseInt(id.trim()));
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 find 特定Event 的 Id （通过Name）
     */
    public String getEventGroupId(String serviceName, String eventName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("eventName: " + eventName);

        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig method = service.findEventByName(eventName);
            if (null != method) {
            	return Integer.toString(method.getGroupId());
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            	return null;
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        	return null;
        }
    }

    /**
     * 在指定服务中 修改 特定Event 的 RPCSpecificType （通过Name）
     */
    public void setEventRPCSpecificType(String serviceName, String eventName, String speType) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("eventName: " + eventName);
    	AutorsarCommonUtils.logEx("speType: " + speType);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig method = service.findEventByName(eventName);
            if (null != method) {
            	method.setRPCSpecificType(speType);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Event 的 RPCSpecificType （通过Name）
     */
    public void setEventPara(String serviceName, String eventName, String para) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("eventName: " + eventName);
    	AutorsarCommonUtils.logEx("para: " + para);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig method = service.findEventByName(eventName);
            if (null != method) {
            	method.setEventPara(para);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Event 的 strategy （通过Name）
     */
    public void setEventSendStrategy(String serviceName, String eventName, String strategy) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("eventName: " + eventName);
    	AutorsarCommonUtils.logEx("strategy: " + strategy);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig method = service.findEventByName(eventName);
            if (null != method) {
            	method.setSendStrategy(strategy);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Event 的 CyclicTime （通过Name）
     */
    public void setEventCyclicTime(String serviceName, String eventName, String cTm) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("eventName: " + eventName);
    	AutorsarCommonUtils.logEx("CyclicTime: " + cTm);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig method = service.findEventByName(eventName);
            if (null != method) {
            	method.setCyclicTime(cTm);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    /**
     * 在指定服务中 修改 特定Event 的 RPCType （通过Name）
     */
    public void setEventRPCType(String serviceName, String eventName, String RPCType) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("eventName: " + eventName);
    	AutorsarCommonUtils.logEx("RPCType: " + RPCType);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig method = service.findEventByName(eventName);
            if (null != method) {
            	method.setRPCType(RPCType);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }

    /**
     * Get Field list
     */
    public List<ServiceFieldConfig> getFieldsFromServiceName(String serviceName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            return service.getFields();
        }
        return null;
    }

    /**
     * 向指定服务中添加 Field
     */
    public boolean addFieldToService(String serviceName, ServiceFieldConfig field) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            service.getFields().add(field);
            return true;
        }
        return false;
    }
    
    /**
     * 向指定服务中添加 Field实例，只存储Field name
     */
    public void addFieldentryToService(String serviceName, String fieldName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
        	ServiceFieldConfig entry = new ServiceFieldConfig();
        	entry.setFieldName(fieldName);
            service.getFields().add(entry);
        }
    }

    /**
     * 在指定服务中 检查 特定Field是否存在
     */
    public boolean isFieldOfServiceExist(String serviceName, String fieldName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            return service.isFieldExistFromName(fieldName);
        }
        return false;
    }

    /**
     * 在指定服务中 检查 特定Field是否存在,如果不存在则创建这个Field
     */
    public void creatFieldOfServiceIfNotExist(String serviceName, String fieldName) {
        if (serviceExistStatus(serviceName) == false) {
        	AutorsarCommonUtils.logEx("服务不存在: " + serviceName);
        	return;
        }
        
        if (isFieldOfServiceExist(serviceName, fieldName) == false) {
        	addFieldentryToService(serviceName, fieldName);
        }
    }

    /**
     * 在指定服务中 删除 特定Field
     */
    public boolean removeFieldFromService(String serviceName, String fieldName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            List<ServiceFieldConfig> fields = service.getFields();
            return fields.removeIf(field -> field.getFieldName().equals(fieldName));
        }
        return false;
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 ID （通过Name）
     */
    public void setFieldID(String serviceName, String fieldName, String id) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("FieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("id: " + id);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig method = service.findFieldByName(fieldName);
            if (null != method) {
            	method.setFieldId(Integer.parseInt(id.trim()));
            } else {
            	AutorsarCommonUtils.logEx("Field is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 protocol （通过Name）
     */
    public void setFieldProtocol(String serviceName, String fieldName, String protocol) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("protocol: " + protocol);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setRPCProtocol(protocol);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 protocol （通过Name）
     */
    public String getFieldProtocol(String serviceName, String fieldName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);

        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	return field.getRPCProtocol();
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            	return null;
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        	return null;
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 Group Name （通过Name）
     */
    public void setFieldGroupName(String serviceName, String fieldName, String gName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("gName: " + gName);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setGroupName(gName);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    

    /**
     * 在指定服务中 修改 特定Field 的 Group Id （通过Name）
     */
    public void setFieldGroupId(String serviceName, String fieldName, String id) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("id: " + id);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setGroupId(Integer.parseInt(id.trim()));
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }

    /**
     * 在指定服务中 修改 特定Field 的 RPCSpecificType （通过Name）
     */
    public void setFieldRPCSpecificType(String serviceName, String fieldName, String RPCSpecificType) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("RPCSpecificType: " + RPCSpecificType);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setRPCSpecificType(RPCSpecificType);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 PropertyName （通过Name）
     */
    /*public void setFieldPropertyName(String serviceName, String fieldName, String PropertyName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("PropertyName: " + PropertyName);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setPropertyName(PropertyName);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }*/
    
    /**
     * 在指定服务中 修改 特定Field 的 PropertyDataType （通过Name）
     */
    /*
    public void setFieldPropertyDataType(String serviceName, String fieldName, String PropertyDataType) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("PropertyDataType: " + PropertyDataType);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setPropertyDataType(PropertyDataType);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }*/
    
    /**
     * 在指定服务中 修改 特定Field 的 EventPara （通过Name）
     */
    public void setFieldEventPara(String serviceName, String fieldName, String EventPara) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("EventPara: " + EventPara);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setEventPara(EventPara);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 GetterStatus （通过Name）
     */
    public void setFieldGetterStatus(String serviceName, String fieldName, boolean status) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("status: " + status);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setGetterStatus(status);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 SetterStatus （通过Name）
     */
    public void setFieldSetterStatus(String serviceName, String fieldName, boolean status) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("status: " + status);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setSetterStatus(status);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 NotifierStatus （通过Name）
     */
    public void setFieldNotifierStatus(String serviceName, String fieldName, boolean status) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("status: " + status);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setNotifierStatus(status);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }

    /**
     * 在指定服务中 修改 特定Field 的 RPCType （通过Name）
     */
    public void setFieldRPCType(String serviceName, String fieldName, String RPCType) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("RPCType: " + RPCType);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setRPCType(RPCType);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 getter name （通过 service Name & field name）
     */
    public void setFieldGetterName(String serviceName, String fieldName, String getterName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("getterName: " + getterName);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setGetterName(getterName);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 getter id （通过 service Name & field name）
     */
    public void setFieldGetterID(String serviceName, String fieldName, String getterID) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("getterID: " + getterID);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setGetterID(getterID);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 getter getterProtocol （通过 service Name & field id）
     */
    public void setFieldGetterProtocol(String serviceName, String fieldName, String getterProtocol) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("getterProtocol: " + getterProtocol);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setGetterProtocol(getterProtocol);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 getter getterProtocol （通过 service Name & field id）
     */
    public String getFieldGetterProtocol(String serviceName, String fieldName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);

        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	return field.getGetterProtocol();
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            	return null;
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        	return null;
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 setter name （通过 service Name & field id）
     */
    public void setFieldSetterName(String serviceName, String fieldName, String setterName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("setterName: " + setterName);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setSetterName(setterName);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 setter id （通过 service Name & field id）
     */
    public void setFieldSetterID(String serviceName, String fieldName, String setterID) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("setterID: " + setterID);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setSetterID(setterID);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 setter setterProtocol （通过 service Name & field id）
     */
    public void setFieldSetterProtocol(String serviceName, String fieldName, String setterProtocol) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("setterProtocol: " + setterProtocol);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setSetterProtocol(setterProtocol);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 setter setterProtocol （通过 service Name & field id）
     */
    public String getFieldSetterProtocol(String serviceName, String fieldName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);

        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	return field.getSetterProtocol();
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            	return null;
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        	return null;
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 notifier name （通过 service Name & field id）
     */
    public void setFieldNotifierName(String serviceName, String fieldName, String notifierName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("notifierName: " + notifierName);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setNotifierName(notifierName);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 notifier id （通过 service Name & field id）
     */
    public void setFieldNotifierId(String serviceName, String fieldName, String notifierID) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("notifierID: " + notifierID);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setNotifierID(notifierID);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 notifier Protocol （通过 service Name & field id）
     */
    public void setFieldNotifierProtocol(String serviceName, String fieldName, String notifierProtocol) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);
    	AutorsarCommonUtils.logEx("notifierProtocol: " + notifierProtocol);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	field.setNotifierProtocol(notifierProtocol);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Field 的 notifier Protocol （通过 service Name & field id）
     */
    public String getFieldNotifierProtocol(String serviceName, String fieldName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("fieldName: " + fieldName);

        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByName(fieldName);
            if (null != field) {
            	return field.getNotifierProtocol();
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +fieldName);
            	return null;
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        	return null;
        }
    }

    /**
     * 向指定服务中添加 Method
     */
    public boolean addMethodToService(String serviceName, ServiceMethodConfig method) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            service.getMethods().add(method);
            return true;
        }
        return false;
    }

    /**
     * 向指定服务中添加 Method实例，只存储Method name
     */
    public void addMethodentryToService(String serviceName, String methodName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
        	ServiceMethodConfig entry = new ServiceMethodConfig();
        	entry.setMethodName(methodName);
            service.getMethods().add(entry);
        }
    }

    /**
     * 在指定服务中 检查 特定Method是否存在
     */
    public boolean isMethodOfServiceExist(String serviceName, String methodName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            return service.isMethodExistFromName(methodName);
        }
        return false;
    }

    /**
     * 在指定服务中 检查 特定Method是否存在,如果不存在则创建这个method
     */
    public void creatMethodOfServiceIfNotExist(String serviceName, String methodName) {
        if (serviceExistStatus(serviceName) == false) {
        	AutorsarCommonUtils.logEx("服务不存在: " + serviceName);
        	return;
        }
        
        if (isMethodOfServiceExist(serviceName, methodName) == false) {
        	addMethodentryToService(serviceName, methodName);
        }
    }

    /**
     * 在指定服务中 删除 特定Method
     */
    public boolean removeMethodFromService(String serviceName, String methodName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            List<ServiceMethodConfig> methods = service.getMethods();
            return methods.removeIf(method -> method.getMethodName().equals(methodName));
        }
        return false;
    }

    

    /**
     * 在指定服务中 修改 特定Method 的 ID （通过Name）
     */
    public void setMethodID(String serviceName, String methodName, String id) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("methodName: " + methodName);
    	AutorsarCommonUtils.logEx("id: " + id);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceMethodConfig method = service.findMethodByName(methodName);
            if (null != method) {
            	method.setMethodId(Integer.parseInt(id.trim()));
            } else {
            	AutorsarCommonUtils.logEx("Method is NULL: " +methodName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }

    /**
     * 在指定服务中 修改 特定Method 的 protocol （通过Name）
     */
    public void setMethodProtocol(String serviceName, String methodName, String protocol) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("methodName: " + methodName);
    	AutorsarCommonUtils.logEx("protocol: " + protocol);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceMethodConfig method = service.findMethodByName(methodName);
            if (null != method) {
            	method.setRPCProtocol(protocol);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +methodName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Method 的 protocol （通过Name）
     */
    public String getMethodProtocol(String serviceName, String methodName) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("methodName: " + methodName);

        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceMethodConfig method = service.findMethodByName(methodName);
            if (null != method) {
            	return method.getRPCProtocol();
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +methodName);
            	return null;
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        	return null;
        }
    }
    
    /**
     * 在指定服务中 修改 特定Method 的 RPCSpecificType （通过Name）
     */
    public void setMethodRPCSpecificType(String serviceName, String methodName, String RPCSpecificType) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("methodName: " + methodName);
    	AutorsarCommonUtils.logEx("RPCSpecificType: " + RPCSpecificType);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceMethodConfig method = service.findMethodByName(methodName);
            if (null != method) {
            	method.setRPCSpecificType(RPCSpecificType);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +methodName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Method 的 RPCType （通过Name）
     */
    public void setMethodRPCType(String serviceName, String methodName, String RPCType) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("methodName: " + methodName);
    	AutorsarCommonUtils.logEx("RPCType: " + RPCType);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceMethodConfig method = service.findMethodByName(methodName);
            if (null != method) {
            	method.setRPCType(RPCType);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +methodName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }

    /**
     * 在指定服务中 修改 特定Method 的 RPCType （通过Name）
     */
    public void setMethodInputPara(String serviceName, String methodName, String InputPara) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("methodName: " + methodName);
    	AutorsarCommonUtils.logEx("InputPara: " + InputPara);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceMethodConfig method = service.findMethodByName(methodName);
            if (null != method) {
            	method.setInputPara(InputPara);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +methodName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Method 的 OutputPara （通过Name）
     */
    public void setMethodOutputPara(String serviceName, String methodName, String OutputPara) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("methodName: " + methodName);
    	AutorsarCommonUtils.logEx("OutputPara: " + OutputPara);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceMethodConfig method = service.findMethodByName(methodName);
            if (null != method) {
            	method.setOutputPara(OutputPara);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +methodName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 特定Method 的 setFFFlag （通过Name）
     */
    public void setMethodsetFFFlag(String serviceName, String methodName, String setFFFlag) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("methodName: " + methodName);
    	AutorsarCommonUtils.logEx("setFFFlag: " + setFFFlag);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceMethodConfig method = service.findMethodByName(methodName);
            if (null != method) {
            	method.setFFFlag(setFFFlag);
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +methodName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }

    /**
     * 在指定服务中 修改 Service 的全局 Group name （通过Name）
     */
    public void setGroupNameFromService(String serviceName, String name) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("name: " + name);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
        	service.setGroupId(name);
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 Service 的全局 Group Id （通过Name）
     */
    public void setGroupIdFromService(String serviceName, String id) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("id: " + id);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
        	service.setGroupId(id);
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中 修改 Service 的全局 Group name （通过Name）
     */
    public void setPrFlgFromService(String serviceName, String flg) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("flg: " + flg);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
        	service.setPrFlg(flg);
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }
    
    /**
     * 在指定服务中， 根据服务名修改服务ID
     */
    public void setServiceIDFromServiceName(String serviceName, String id) {
        for (ServiceEntry entry : serviceList) {
            if (serviceName.equals(entry.getServiceName())) {
                entry.setServiceId(Integer.parseInt(id.trim()));
                break;
            }
        }
    }

    /**
     * 如果是，返回服务名称，如果不是返回null
     */
    public String isNameAEvent(String name) {
    	for (ServiceEntry entry : serviceList) {
    		ServiceEventConfig event = entry.findEventByName(name);
            if (null != event) {
            	return entry.getServiceName();
            } 
    	}

    	return null;
    }

    public boolean isNameAEventOfService(String serviceName, String eventName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceEventConfig event = service.findEventByName(eventName);
            if (null != event) {
            	return true;
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +eventName);
            	return false;
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        	return false;
        }
    }
    
    /**
     * 如果是，返回服务名称，如果不是返回null
     */
    public String isNameAFieldNotifier(String name) {
    	for (ServiceEntry entry : serviceList) {
    		if (true == entry.isNameBelongFieldNotifier(name)) {
    			return entry.getServiceName();
    		}
    	}

    	return null;
    }
    
    public boolean isNameAFieldNotifierOfService(String serviceName, String notifierName) {
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByNotifierName(notifierName);
            if (null != field) {
            	return true;
            } else {
            	AutorsarCommonUtils.logEx("eventName is NULL: " +notifierName);
            	return false;
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        	return false;
        }
    }
    
    //通过服务名和notifier name 设置 groupid， 对于field而言，只有notifier有group id， setter和getter都没有
    public void setFieldNotifierGroupId(String serviceName, String notifierName, String id) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("notifierName: " + notifierName);
    	AutorsarCommonUtils.logEx("id: " + id);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByNotifierName(notifierName);
            if (null != field) {
            	field.setGroupId(Integer.parseInt(id.trim()));
            } else {
            	AutorsarCommonUtils.logEx("notifierName is NULL: " +notifierName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }

    //通过服务名和notifier name 设置 group name， 对于field而言，只有notifier有group id， setter和getter都没有
    public void setFieldNotifierGroupName(String serviceName, String notifierName, String name) {
    	AutorsarCommonUtils.logEx("serviceName: " + serviceName);
    	AutorsarCommonUtils.logEx("notifierName: " + notifierName);
    	AutorsarCommonUtils.logEx("name: " + name);
        ServiceEntry service = getServiceByName(serviceName);
        if (service != null) {
            ServiceFieldConfig field = service.findFieldByNotifierName(notifierName);
            if (null != field) {
            	field.setGroupName(name);
            } else {
            	AutorsarCommonUtils.logEx("notifierName is NULL: " +notifierName);
            }
        } else {
        	AutorsarCommonUtils.logEx("service is NULL: " +serviceName);
        }
    }

    public ServiceEventConfig getEventEntryFromGroupName(String serviceName, String groupName) {
    	List <ServiceEventConfig> events = getEventsFromServiceName(serviceName);
    	if (events != null && !events.isEmpty()) {
    		for (ServiceEventConfig event: events) {
    			if (event.getGroupName().equals(groupName)) {
    				return event;
    			}
    		}
    	} else {
    		AutorsarCommonUtils.logEx("service is NULL: " +serviceName + " Has No event");
    	}
    	
    	return null;
    }

    public ServiceFieldConfig getFieldEntryFromGroupName(String serviceName, String groupName) {
    	List <ServiceFieldConfig> fields = getFieldsFromServiceName(serviceName);
    	if (fields != null && !fields.isEmpty()) {
    		for (ServiceFieldConfig field: fields) {
    			if (field.getGroupName().equals(groupName)) {
    				return field;
    			}
    		}
    	} else {
    		AutorsarCommonUtils.logEx("service is NULL: " +serviceName + " Has No field");
    	}
    	
    	return null;
    }

    public String getGroupIPFromName(String serviceName, String groupName) {
    	ServiceEventConfig event = getEventEntryFromGroupName(serviceName, groupName);
    	if (null != event) {
    		return event.getEventGroupMutiIP();
    	} else {
    		ServiceFieldConfig field = getFieldEntryFromGroupName(serviceName, groupName);
    		if (null != field) {
    			return field.getFieldGroupMutiIP();
    		}
    	}

    	return null;
    }

    public String getGroupPortFromName(String serviceName, String groupName) {
    	ServiceEventConfig event = getEventEntryFromGroupName(serviceName, groupName);
    	if (null != event) {
    		return event.getEventGroupMutiPort();
    	} else {
    		ServiceFieldConfig field = getFieldEntryFromGroupName(serviceName, groupName);
    		if (null != field) {
    			return field.getFieldGroupMutiPort();
    		}
    	}

    	return null;
    }
}
